package com.qf.config;

import com.qf.web.interceptor.LoginInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.*;

/**
 * springmvc配置类，替代springmvc.xml配置文件
 */

@ComponentScan("com.qf.web")
@EnableWebMvc
public class SpringMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/js/**").addResourceLocations("/js/");
        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
        registry.addResourceHandler("/html/**").addResourceLocations("/html/");
        registry.addResourceHandler("/imgs/**").addResourceLocations("/imgs/");
    }


    /*
        启用默认Servlet，可以和addResourceHandlers实现相同的效果--静态资源放行
     */
//    @Override
//    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
//        configurer.enable();
//    }



    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/js/**","/css/**","/imgs/**")
                .excludePathPatterns("/html/login.html","/html/regist.html","/user/login","/user/regist");
    }
}
